package com.example.demo1.service.impl;

import com.example.demo1.dto.FruitWeightDto;
import com.example.demo1.service.CalculateAmountService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class CalculateAmountServiceImpl implements CalculateAmountService {

    /**
     * 苹果单价
     */
    public static final BigDecimal APPLE_PRICE = BigDecimal.valueOf(8);

    /**
     * 草莓单价
     */
    public static final BigDecimal STRAWBERRY_PRICE = BigDecimal.valueOf(13);

    /**
     * 芒果单价
     */
    public static final BigDecimal MANGO_PRICE = BigDecimal.valueOf(20);

    @Override
    public BigDecimal calculateOne(FruitWeightDto dto) {
        BigDecimal appleAmount = BigDecimal.valueOf(dto.getAppleWeight()).multiply(APPLE_PRICE);
        BigDecimal strawberryAmount = BigDecimal.valueOf(dto.getStrawberryWeight()).multiply(STRAWBERRY_PRICE);
        return appleAmount.add(strawberryAmount);
    }

    @Override
    public BigDecimal calculateTwo(FruitWeightDto dto) {
        BigDecimal appleAmount = BigDecimal.valueOf(dto.getAppleWeight()).multiply(APPLE_PRICE);
        BigDecimal strawberryAmount = BigDecimal.valueOf(dto.getStrawberryWeight()).multiply(STRAWBERRY_PRICE);
        BigDecimal mangoAmount = BigDecimal.valueOf(dto.getMangoWeight()).multiply(MANGO_PRICE);
        return appleAmount.add(strawberryAmount).add(mangoAmount);
    }

    @Override
    public BigDecimal calculateThree(FruitWeightDto dto) {
        BigDecimal appleAmount = BigDecimal.valueOf(dto.getAppleWeight()).multiply(APPLE_PRICE);
        BigDecimal strawberryAmount = BigDecimal.valueOf(dto.getStrawberryWeight()).multiply(STRAWBERRY_PRICE).multiply(BigDecimal.valueOf(0.8));
        BigDecimal mangoAmount = BigDecimal.valueOf(dto.getMangoWeight()).multiply(MANGO_PRICE);
        return appleAmount.add(strawberryAmount).add(mangoAmount);
    }

    @Override
    public BigDecimal calculateFour(FruitWeightDto dto) {
        BigDecimal appleAmount = BigDecimal.valueOf(dto.getAppleWeight()).multiply(APPLE_PRICE);
        BigDecimal strawberryAmount = BigDecimal.valueOf(dto.getStrawberryWeight()).multiply(STRAWBERRY_PRICE).multiply(BigDecimal.valueOf(0.8));
        BigDecimal mangoAmount = BigDecimal.valueOf(dto.getMangoWeight()).multiply(MANGO_PRICE);
        BigDecimal sumAmount = appleAmount.add(strawberryAmount).add(mangoAmount);
        if (sumAmount.compareTo(BigDecimal.valueOf(100)) >= 0) {
            return sumAmount.subtract(BigDecimal.valueOf(10));
        } else {
            return sumAmount;
        }
    }
}




